//
// Created by bleedingfight on 2020/7/1.
//
#include "sqrt.h"
#include <iostream>
int mySqrt(int n) {
<<<<<<< HEAD:cxx/algorithm/src/sqrt.cc
  if (n == 0)
    return 0;
  double x_current = 0;
  double x_next = n / 2;
  while (x_current != x_next) {
    x_current = x_next;
    x_next = (x_current + n / x_current) / 2;
  }
  return int(x_current);
=======
    if (n == 0)
        return 0;
    double x_current = 0;
    double x_next = n / 2;
    while (x_current != x_next) {
        x_current = x_next;
        x_next = (x_current + n / x_current) / 2;
    }
    return int(x_current);
}

int mySqrtDiv(int x) {
    if (x <= 1)
        return x;
    else {
        int lower = 0;
        int upper = x;
        int middle = 0;
        long long int double_value = 0;
        while ((upper - lower) != 1) {
            middle = (lower + upper) / 2;
            double_value = (long)middle * middle;
            if (double_value == x)
                return middle;
            else if (double_value > x)
                upper = middle;
            else
                lower = middle;
        }
        return lower;
    }
>>>>>>> dev:cxx/algorithm/common/src/sqrt.cc
}
